''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  Module                       :    Fund Format Class
'  Datalayer's Methods Used     :    N/A
'  Purpose                      :    BusinessLayer Methods used in frmFundFormat,frmFundAddFormat,frmImportFund
'  <Class     14/May/2007  Sukhjinder Singh> 

Imports System.Data.SqlClient
Imports Crystal.DatabaseManagement
Imports Crystal.DatabaseManagement.BusinessLayer

Public Class cFundFormat

#Region "Declare"
    Private strFormatName As String = ""
    Private dDate As Date
    Private _UserId As Integer
    Private _FormatId As Integer
    Private _FileColumn As String = ""
    Private _DBFieldId As Integer
    Private _Displayname As String = ""
#End Region

#Region "Properties"

    Public Property FormatName() As String
        Get
            Return strFormatName
        End Get
        Set(ByVal value As String)
            strFormatName = value
        End Set
    End Property

    Public Property DisplayName() As String
        Get
            Return _Displayname
        End Get
        Set(ByVal value As String)
            _Displayname = value
        End Set
    End Property

    Public Property CdDate() As Date
        Get
            Return dDate
        End Get
        Set(ByVal value As Date)
            dDate = value
        End Set
    End Property

    Public Property intUserId() As Integer
        Get
            Return _UserId
        End Get
        Set(ByVal value As Integer)
            _UserId = value
        End Set
    End Property

    Public Property FormatId() As Integer
        Get
            Return _FormatId
        End Get
        Set(ByVal value As Integer)
            _FormatId = value
        End Set
    End Property

    Public Property DBFieldId() As Integer
        Get
            Return _DBFieldId
        End Get
        Set(ByVal value As Integer)
            _DBFieldId = value
        End Set
    End Property

    Public Property FileColumn() As String
        Get
            Return _FileColumn
        End Get
        Set(ByVal value As String)
            _FileColumn = value
        End Set
    End Property

#End Region

#Region "Transaction"

    ''' <summary>
    ''' 'To Insert New Fund Format
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function Insert() As ExecutionResult
        'Const ARRAY_SIZE As Integer = 3
        Dim ReturnVal As ExecutionResult = Nothing
        Dim Param(3) As SqlClient.SqlParameter
        'Try

        Param(0) = New SqlParameter("@formatname", strFormatName)
        Param(1) = New SqlParameter("@date", dDate)
        Param(2) = New SqlParameter("@userid", _UserId)
        Param(3) = New SqlParameter("@FormatId", SqlDbType.Int)
        Param(3).Direction = ParameterDirection.Output
        Param(3).Value = 0
        ReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_ADD_FundFormat", CommandType.StoredProcedure, ReturnTypes.NonQuery, Param)
        Return ReturnVal
        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    Param = Nothing
        'End Try
    End Function

    ''' <summary>
    ''' To Select Fund FormatId and FormatName
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function [Select]() As IDataReader
        Dim eReturnVal As ExecutionResult = Nothing
        'Try

        eReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_SEL_FundFormatName", CommandType.StoredProcedure, ReturnTypes.DataReader)

        Return CType(eReturnVal.ResultObject, IDataReader)
        'Catch ex As Exception
        '    Throw ex
        'End Try
    End Function

    ''' <summary>
    ''' 'To Insert into cp_FundImportFields
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function InsertFundFields() As ExecutionResult
        'Const ARRAY_SIZE As Integer = 3
        Dim ReturnVal As ExecutionResult = Nothing
        Dim Param(3) As SqlClient.SqlParameter
        'Try


        Param(0) = New SqlParameter("@formatID", _FormatId)
        Param(1) = New SqlParameter("@filecolumn", _FileColumn)
        Param(2) = New SqlParameter("@dbfieldID", _DBFieldId)
        'param(3) = New SqlParameter("@Status", strStatus)
        Param(3) = New SqlParameter("@FieldID", SqlDbType.Int)
        Param(3).Direction = ParameterDirection.Output
        Param(3).Value = 0
        'param(1) = New SqlParameter("@ReturnVal", SqlDbType.Int)
        'param(1).Direction = ParameterDirection.Output
        'param(1).Value = 0
        ReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_FND_ADD_FundFields", CommandType.StoredProcedure, ReturnTypes.NonQuery, Param)
        Return ReturnVal
        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    Param = Nothing
        'End Try
    End Function

    ''' <summary>
    '''  'To Select Mapped Fields List and get DataBase Fields ID, from cp_fundImportfields
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function SelectMapDataBaseFields() As Integer
        Dim ReturnVal As ExecutionResult = Nothing
        Dim IDisplayID As Integer
        'Const ARRAY_SIZE As Integer = 2
        'Try
        Dim param(2) As SqlClient.SqlParameter
        param(0) = New SqlParameter("@formatID", _FormatId)
        param(1) = New SqlParameter("@displayname", DisplayName)
        param(2) = New SqlParameter("@DBFieldID", SqlDbType.Int)
        param(2).Direction = ParameterDirection.Output
        ReturnVal = CoreFunctions.Execute(strConfiguration, "Cp_sp_FND_EXT_FundDataBaseFields", CommandType.StoredProcedure, ReturnTypes.NonQuery, param)
        IDisplayID = ReturnVal.ResultParamenters(2).Value
        Return IDisplayID
        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    ReturnVal = Nothing
        'End Try
    End Function

    ''' <summary>
    '''   'To Delete an Selective Fund Mapped FormatId from cp_fundImportfield
    ''' </summary>
    ''' <param name="FormatID"></param>
    ''' <remarks></remarks>

    Public Sub DeleteFundMapping(ByVal FormatID As Integer)
        Dim ReturnVal As ExecutionResult = Nothing
        'Const ARRAY_SIZE As Integer = 0
        ' Try

        Dim param(0) As SqlClient.SqlParameter
        param(0) = New SqlParameter("@FormatID", FormatID)

        ReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_FND_DEL_FundImportFieldMapping", CommandType.StoredProcedure, ReturnTypes.NonQuery, param)

        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    ReturnVal = Nothing
        'End Try
    End Sub

    ''' <summary>
    '''    'To Get the Mandatory DataFields from cp_FundDataBaseFields
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function GetMandatoryFundField() As IDataReader
        Dim ReturnVal As ExecutionResult = Nothing
        'Dim MandatoryFields As DataSet = Nothing
        'Try
        ReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_FND_SEL_MandatoryFundImportDatabaseFields", CommandType.StoredProcedure, ReturnTypes.DataReader)
        Return CType(ReturnVal.ResultObject, IDataReader)
        'Return MandatoryFields
        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    ReturnVal = Nothing
        'End Try
    End Function

    ''' <summary>
    '''  'To Get the Display Fields name from cp_FundDataBaseFields
    ''' </summary>
    ''' <param name="DatabaseFieldId"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function GetFundDataBaseFieldName(ByVal DatabaseFieldId As Integer) As String
        Dim ReturnVal As ExecutionResult = Nothing
        Dim DataBaseFieldName As String
        'Const ARRAY_SIZE As Integer = 1
        Dim Param(1) As SqlClient.SqlParameter
        'Try


        Param(0) = New SqlParameter("@DatabaseFieldId", DatabaseFieldId)
        Param(1) = New SqlParameter("@DisplayName ", SqlDbType.VarChar, 30)
        Param(1).Direction = ParameterDirection.Output
        ReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_FND_SEL_FunddatabaseFieldName", CommandType.StoredProcedure, ReturnTypes.Scalar, Param)
        DataBaseFieldName = CType(ReturnVal.ResultParamenters(1).Value, String)
        Return DataBaseFieldName
        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    Param = Nothing
        '    ReturnVal = Nothing
        'End Try
    End Function

    ''' <summary>
    '''  'To Check Mandatory fields Already Mapped
    ''' </summary>
    ''' <param name="FormatID"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>

    Public Function CheckExistenceFundField(ByVal FormatID As Integer) As Boolean
        Dim eReturnVal As ExecutionResult = Nothing
        Dim boolFlag As Boolean
        'Const ARRAY_SIZE As Integer = 1
        Dim param(1) As SqlClient.SqlParameter
        ' Try

        param(0) = New SqlParameter("@FormatId", FormatID)

        param(1) = New SqlParameter("@CheckMandatoryFieldsAlreadyExist", SqlDbType.Bit)
        param(1).Direction = ParameterDirection.Output
        eReturnVal = CoreFunctions.Execute(strConfiguration, "CP_sp_FND_EXT_FundMandatoryFieldsAlreadyExist", CommandType.StoredProcedure, ReturnTypes.Scalar, param)
        boolFlag = CType(eReturnVal.ResultParamenters(1).Value, Boolean)
        Return boolFlag
        'Catch ex As Exception
        '    Throw ex
        'Finally
        '    param = Nothing
        'End Try
    End Function

#End Region
   
End Class
